package com.study.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author study
 * @version 1.0
 * @date 2020/8/22 15:08
 */
@Slf4j
@RestController
public class SendMsgController {

    private final String exchange_name = "java.exchange";
    private final String queue_name = "hello-java-queue";
    private final String key = "hello2.java";

    @Resource
    RabbitTemplate rabbitTemplate;

    @GetMapping("send")
    public String sendMsg() {
        rabbitTemplate.convertAndSend(exchange_name, key,
                "hello world msg",
                //消息的唯一ID
                new CorrelationData(String.valueOf(System.currentTimeMillis()))
        );
        log.info("消息发送完成");
        return new Date().toString();
    }
}
